package cn.bnuz.edu.todolist.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class TodoDBHelper extends SQLiteOpenHelper {
    private static final int DB_VERSION = 1;
    private static final String DB_NAME = "todolist.db";
    public static String TABLE_NAME;
    private Context context;

    public TodoDBHelper(Context context, String name) {
        super(context, DB_NAME, null, DB_VERSION);
        this.context = context;
        TABLE_NAME = name;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME +
                "(_id Integer PRIMARY KEY AUTOINCREMENT, TodoTitle Text, TodoTime Text, isCompleted Boolean)";
        sqLiteDatabase.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        String sql = "DROP TABLE IF EXISTS " + TABLE_NAME;
        sqLiteDatabase.execSQL(sql);
        onCreate(sqLiteDatabase);
    }
}
